package com.xyzq.dao.ya.hibernate;

import java.util.Date;
import java.util.List;

import org.appfuse.dao.hibernate.GenericDaoHibernate;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.xyzq.dao.ya.AccountDAO;
import com.xyzq.model.ya.data.Account;

@Repository("accountDao")
public class AccountDaoHibernate extends GenericDaoHibernate<Account, Long>
		implements AccountDAO {

	public AccountDaoHibernate() {
		super(Account.class);
	}

	public Account findByAccountId(Integer accountId) {
		// TODO Auto-generated method stub
		List<Account> list = this.getHibernateTemplate().find(
				"from Account where account=?", accountId);
		if (!list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}

	public List<Account> findAccountWithDate(Date start, Date end) {
		// TODO Auto-generated method stub
		List list = this.getHibernateTemplate().find(
				"from Account where openDay>=? and openDay<=?", start, end);
		if (list.isEmpty()) {
			return null;
		}
		return list;

	}

	public List<Account> findShAccountWithDate(Date start, Date end) {
		// TODO Auto-generated method stub
		List list = this
				.getHibernateTemplate()
				.find("from Account where stock_sh_openday>=? and stock_sh_openday<=?",
						start, end);
		if (list.isEmpty()) {
			return null;
		}
		return list;
	}

	public List<Account> findSzAccountWithDate(Date start, Date end) {
		// TODO Auto-generated method stub
		List list = this
				.getHibernateTemplate()
				.find("from Account where stock_sz_openday>=? and stock_sz_openday<=? and stock_sh_openday is null",
						start, end);
		if (list.isEmpty()) {
			return null;
		}
		return list;
	}

	public List<Account> findByAccountOrName(Integer account, String name) {
		// TODO Auto-generated method stub
		List list = this.getHibernateTemplate().find(
				"from Account where account=? or name=?", account, name);
		if (list.isEmpty()) {
			return null;
		}
		return list;
	}

}
